import {
    CREATE_THREAD_SUCCESS,
    FETCH_THREAD_SUCCESS
} from '../actions'

import { hashHistory } from 'react-router'

export default function (state = { resources: null}, action) {
    switch(action.type) {
        case CREATE_THREAD_SUCCESS:
            const { uuid } = action.response;
            setTimeout(() => hashHistory.push(`/thread/${uuid}`), 0)
            return {
                ...state,
                resources: action.response
            }
        case FETCH_THREAD_SUCCESS:
            return {
                ...state,
                resources: action.response
            }
        default:
            return state;
    }
}
